class State:
    def __init__(self):
        self.end = None
    def next(self, e):
        pass

class S4(State):
    def __init__(self):
        self.end = False
    def next(self, e):
        if isinstance(e, int): return S3()
        else: return None

class S3(State):
    def __init__(self):
        self.end = True
    def next(self, e):
        if isinstance(e, int): return self
        return None

class S2(State):
    def __init__(self):
        self.end = True
    def next(self, e):
        if isinstance(e, int) and 0<=e<=9: return self
        elif isinstance(e, str) and e=='.': return S3()
        else: return None

class S6(State):
    def __init__(self):
        self.end = False
    def next(self, e):
        if isinstance(e, int): return S2()
        elif e=='.': return S4()
        return None


class S(State):
    def __init__(self):
        self.end = False
    def next(self, e):
        if isinstance(e, int): return S2()
        elif e=='.': return S4()
        elif e=='-' or e=='+': return S6()
        return None

class Solution(object):
    def isNumber(self, s):
        """
        :type s: str
        :rtype: bool
        """
        s = s.strip()
        acc = []
        for c in s:
            if ord('0')<=ord(c)<=ord('9'): acc.append(int(c))
            elif c=='.': acc.append('.')
            elif c=='e': acc.append('e')
            elif c=='-': acc.append('-')
            elif c=='+': acc.append('+')
            else: return False
        if acc.count('e')>1: return False

        def isNum(arr):
            s = S()
            for a in arr:
                s = s.next(a)
                if s==None:
                    return False
            return s.end
        
        if acc.count('e'):
            i = acc.index('e')
            return isNum(acc[:i]) and isNum(acc[i+1:])
        else:
            return isNum(acc)

print(Solution().isNumber('+.8'))